<template>
  <div class="home-new">
    <HomePanel title="新鲜好物" subTitle="新鲜出炉 品质靠谱">
      <!-- 右上角插槽 -->
      <template #right><XtxMore path="/"></XtxMore></template>
      <div ref="target" style="position:relative;height:426px;">
        <!-- 面板内容 -->
        <transition name="fade">
          <ul class="goods-list" v-if="goods.length">
            <li v-for="item in goods" :key="item.id">
              <router-link :to="`/product/${item.id}`">
                <img :src="item.picture" alt="">
                <p class="name ellipsis">{{item.name}}</p>
                <p class="price">&yen;{{item.price}}</p>
              </router-link>
            </li>
          </ul>
          <!-- 没有数据显示骨架 -->
          <HomeSkeleton v-else bg="#f0f9f4"></HomeSkeleton>
        </transition>
      </div>
    </HomePanel>
  </div>
</template>

<script>

import HomePanel from './home-panel.vue'
import HomeSkeleton from './home-skeleton.vue'
import { useLazyData } from '@/hooks'
import { findNew } from '@/api/home'

export default {
  name: 'HomeNew',
  components: {
    HomePanel,
    HomeSkeleton
  },
  setup () {
    /* findNew().then(data => {
      goods.value = data.result
    }) */
    // 数据懒加载
    const { result, target } = useLazyData(findNew)
    return { goods: result, target }
  }
}
</script>

<style lang="less" scoped>
.goods-list{
  display:flex;
  justify-content: space-between;
  height:406px;
  li {
    width: 306px;
    height: 406px;
    background: #e7faf0;
    .hoverShadow();
    img{
      width: 306px;
      height: 306px;
    }
    p{
      font-size: 22px;
      padding:12px 30px 0 30px;
      text-align: center;
    }
    .price{
      color:@priceColor;
    }
  }
}
.fade{
  &-leave {
    &-active {
      position: absolute;
      width: 100%;
      transition: opacity .5s .2s;
      z-index: 1;
    }
    &-to {
      opacity: 0;
    }
  }
}
</style>
